function  uniwrite_bpr(data_ord,data_abs,header,absspc,FileName,status)
%UNIWRITE   writes an Universal File Type 58
%           uniwrite(data,header,FileName, status)
%           
%           data_ord real or complex ordinate data
%           data_abs real abscissa data
%           header   header made with UNIVHEAD or HEADCONV
%           absspc   1 = even abscissa spacing (no abs values stored)
%                    0 = uneven abscissa spacing
%           FileName name of target file, use extension .unv
%           status   1 means create file, first data block
%                    2 means add to existing file
%           See the manual describing the header format. 
%           UNIWRITE is meant to be a simple file translator for time or FRF data.
%           See also UNIVHEAD, HEADCONV, UNIVREAD


%   Copyright 2001, Saven EduTech AB. 
%   Revision: 1.3  Date: 2001-12-03
%   Revision history
%   2001-10-29  status added to allow contiguous file
%   2001-12-03  last row corrected
%   2003-08-25  Modified by Brian Ross to add option of uneven abscissa spacing

if status == 1;fid = fopen(FileName,'w');end
if status == 2;fid = fopen(FileName,'a');end
%
% start of file -1
% and file type 58
%
fprintf(fid,'%6d%s\n',-1,blanks(74));
fprintf(fid,'%6d%s\n',58,blanks(74));
%
% Header
%
% Ordinate data type and number of data values in rec7
%
odtype = 5;
if isreal(data_ord);odtype = 2;end
datval = length(data_ord);
rec = sprintf('%10i%10i%10i',odtype,datval,absspc);
rec7 = header(7,1:80);
rec7(1:30) = rec;
fprintf(fid,'%s\n',header(1,1:80));
fprintf(fid,'%s\n',header(2,1:80));
fprintf(fid,'%s\n',header(3,1:80));
fprintf(fid,'%s\n',header(4,1:80));
fprintf(fid,'%s\n',header(5,1:80));
fprintf(fid,'%s\n',header(6,1:80));
fprintf(fid,'%s\n',rec7);
fprintf(fid,'%s\n',header(8,1:80));
fprintf(fid,'%s\n',header(9,1:80));
fprintf(fid,'%s\n',header(10,1:80));
fprintf(fid,'%s\n',header(11,1:80));
%
% data
%
if absspc == 1  % even abscissa spacing
	if isreal(data_ord)
       L = length(data_ord);
       m = mod(L,6);
       if m>0
           for i = 1:6-m
               data_ord(L+i) = 0;
           end
       end
       n = 1;
       L = length(data_ord);
       for r = 1:round(L/6)
          r1 = sprspec(data_ord(n));n = n+1;
          r2 = sprspec(data_ord(n));n = n+1;
          r3 = sprspec(data_ord(n));n = n+1;
          r4 = sprspec(data_ord(n));n = n+1;
          r5 = sprspec(data_ord(n));n = n+1;
          r6 = sprspec(data_ord(n));n = n+1;
          rec = [r1,r2,r3,r4,r5,r6];
          fprintf(fid,'%s\n',rec);
       end
	else
	L = length(data_ord);
       m = mod(L,3);
       if m>0
           for i = 1:3-m
               data_ord(L+i) = 0;
           end
       end
       n = 1;
       L = length(data_ord);
       for r = 1:round(L/3)
          r1 = sprspec(real(data_ord(n)));
          r2 = sprspec(imag(data_ord(n)));n = n+1;
          r3 = sprspec(real(data_ord(n)));
          r4 = sprspec(imag(data_ord(n)));n = n+1;
          r5 = sprspec(real(data_ord(n)));
          r6 = sprspec(imag(data_ord(n)));n = n+1;
          rec = [r1,r2,r3,r4,r5,r6];
          fprintf(fid,'%s\n',rec);
       end
	end
else  % uneven abscissa spacing
	if isreal(data_ord)
       L = length(data_ord);
       m = mod(L,3);
       if m>0
           for i = 1:3-m
               data_ord(L+i) = 0;
               data_abs(L+i) = 0;  %  Added 9/8/03
           end
       end
       n = 1;
       L = length(data_ord);
       for r = 1:round(L/3)
          r1 = sprspec(data_abs(n));
          r2 = sprspec(data_ord(n));n = n+1;
          r3 = sprspec(data_abs(n));
          r4 = sprspec(data_ord(n));n = n+1;
          r5 = sprspec(data_abs(n));
          r6 = sprspec(data_ord(n));n = n+1;
          rec = [r1,r2,r3,r4,r5,r6];
          fprintf(fid,'%s\n',rec);
       end
	else
	L = length(data_ord);
       m = mod(L,2);
       if m>0
           for i = 1:2-m
               data_ord(L+i) = 0;
               data_abs(L+i) = 0;  %  Added 9/8/03
          end
       end
       n = 1;
       L = length(data_ord);
       for r = 1:round(L/2)
          r1 = sprspec(real(data_abs(n)));
          r2 = sprspec(real(data_ord(n)));
          r3 = sprspec(imag(data_ord(n)));n = n+1;
          r4 = sprspec(real(data_abs(n)));
          r5 = sprspec(real(data_ord(n)));
          r6 = sprspec(imag(data_ord(n)));n = n+1;
          rec = [r1,r2,r3,r4,r5,r6];
          fprintf(fid,'%s\n',rec);
       end
	end
end
fprintf(fid,'%6d%s\n',-1,blanks(74));
fclose all;
